//子账号管理
(function() {
	var config = require("../_include/config");
	var db = require("../db/index");
	var md5 = require("../_include/md5");
	var helper = require("../_include/helper");
	var db_table_name = config.dbname.busEmployees;
	var db_id_prefix = config.dbIdPrefix.busEmployees;
	var UserCon = require("../user/_con");
	var BusCon = require("../bus/_con");
	//构造函数
	var _con = function(info) {
		var self = this;

		if (!BusCon.get(info.bus_id)) {
			throwCusError("找不到指定商家");
		}
		self.bus_id = info.bus_id;
		self.setInfo(info);

		self._id = db_id_prefix + info.bus_id + ":" + info.name;

		self.create_time = +new Date;
		db.insert(db_table_name, self);
		console.log("设定了一个子账号：", info.name);
	};

	module.exports = _con;

	//技能
	_con.prototype = require("./skill");

	//静态方法
	_con.get = function(Id) {
		var result = db.find_by_id(db_table_name, Id);
		return _con.getInstance(result);
	};
	_con.getInstance = function(obj) {
		if (obj) {
			// var nojson_able_keys = ["pwd"];
			// if (obj.nojson_able_keys instanceof Array) {
			// 	obj.nojson_able_keys = nojson_able_keys;
			// } else {
			// 	Object.defineProperty(obj, "nojson_able_keys", {
			// 		enumerable: false,
			// 		value: nojson_able_keys
			// 	});
			// }
			obj.__proto__ = _con.prototype;
		}
		return obj;
	};
	_con.findByBusId = function(bus_id) {
		return _con.findList({
			bus_id: bus_id
		});
	};
	_con.findList = function(search_obj) {
		var result = db.find_list(db_table_name, search_obj).map(function(obj) {
			return _con.getInstance(obj);
		});
		console.log(search_obj, result.length);
		return result;
	};
}());